package com.ror.java.se.io;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/*
    练习：文件拷贝（每次拷贝一个字节）
    选择一个比较小的文件，不要太大。
 */

public class Demo03Copy {
    public static void main(String[] args) throws IOException {
        long before = System.currentTimeMillis();
        File src = new File("assets/io/byte/ryuko.png");
        File dest = new File("assets/io/byte/copy.png");
        FileInputStream fi = new FileInputStream(src);
        FileOutputStream fo = new FileOutputStream(dest);
        int b;
        while ((b = fi.read()) != -1) {
            fo.write(b);
        }
        //规则：先开的后关
        fo.close();
        fi.close();
        long after = System.currentTimeMillis();
        System.out.println(after - before + "ms took.");
//        dest.delete();
    }
}
